const {
  override,
  addWebpackAlias,
  adjustStyleLoaders,
  addWebpackPlugin,
} = require('customize-cra')
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
/* module.exports = override(
  addWebpackAlias({
    '@': path.resolve(__dirname, './src'),
  }),
  adjustStyleLoaders((rule) => {
    if (rule.test.toString().includes('scss')) {
      rule.use.push({
        loader: require.resolve('sass-resources-loader'),
        options: {
          resources: [
            './src/asset/css/common.scss',
            process.env.NODE_ENV === 'development' ? './src/asset/css/development.scss' : './src/asset/css/build.scss',
          ], //这里是你自己放公共scss变量的路径
        },
      })
    }
  })
)
 */

process.env.GENERATE_SOURCEMAP = 'false'
module.exports = override(
  addWebpackAlias({
    '@': path.resolve(__dirname, './src'),
  }),
  adjustStyleLoaders((rule) => {
    if (rule.test.toString().includes('scss')) {
      rule.use.push({
        loader: require.resolve('sass-resources-loader'),
        options: {
          resources: [
            './src/asset/css/common.scss',
            process.env.NODE_ENV === 'development'
              ? './src/asset/css/development.scss'
              : './src/asset/css/build.scss',
          ], //这里是你自己放公共scss变量的路径
        },
      })
    }
  }),

  process.env.NODE_ENV === 'production' &&
    addWebpackPlugin(
      new CompressionPlugin({
        deleteOriginalAssets: true,
      })
    ),
  (config) => {
    if (process.env.NODE_ENV === 'production') config.devtool = false
    // config.plugins.push(new CompressionPlugin())
    // console.log(config.plugins);
    return config
  }
)
